﻿Imports Aricie.DNN.UI.Controls
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports DotNetNuke.Services.Search
Imports Aricie.DNN.Modules.LuceneSearch.ModuleProviders
Imports Aricie.DNN.Services
Imports Lucene.Net.Documents
Imports System.Security.Cryptography
Imports System.IO
Imports Microsoft.VisualBasic.CompilerServices
Imports DotNetNuke.Services.Localization
Imports Aricie.DNN.Modules.LuceneSearch.Settings
Imports Aricie.DNN.Settings

Namespace Aricie.DNN.Modules.LuceneSearch.UI

    Partial Public Class ResultDetails
        Inherits LuceneModuleBase


        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim guid As String = DotNetNuke.Common.Utilities.UrlUtils.DecryptParameter(Me.Request("guid"))

            Dim queryDriver As PortalQueryingDriver = PortalQueryingDriver.GetByPortalId(PortalId)
            Dim results As LuceneQueryResults = queryDriver.RunQuery(PortalId, New LuceneFilterQuery() With {.FilterQuery = BusinessController.GetQuery(PortalId, String.Format("Uid:*{0}", guid))})

            If results.NbResults > 0 Then


                Dim result As LuceneSearchResultsInfo = CType(results.AsSearchResultsCollection(Me.ModuleID, True)(0), LuceneSearchResultsInfo)
                Dim settings As LuceneResultsSettings = Aricie.DNN.Settings.SettingsController.GetModuleSettings(Of LuceneResultsSettings)(SettingsScope.ModuleSettings, Me.ModuleId)
                Dim template As String = GetItemTemplate(result, Global.Configuration.Templating.Context.TemplateTypes.Details.ToString())

				If settings.DisplayBackButton Then

					pBackLink.Visible = False

				End If

                Dim replace As New AdvancedTokenReplace()

                litTemplate.Text = replace.ReplaceSetTokens(template, result, "Result")

            End If


            lblBack.Text = Localization.GetString("cmdBack.Text")
        End Sub

    End Class

End Namespace
